:- use_module(library(chr)).
:- chr_constraint input/1.
:- chr_constraint preAVG/2.
:- chr_constraint finalAVG/2.

preAVG(X, Y), input(Z) <=> preAVG(A, B), B is Y+1, C is X*Y, A is (C+Z)/B.
input(X) <=> preAVG(X, 1), true.
finalAVG(X, Y), preAVG(Z, Y) ==> X=Z, true.